//
//  MBDGroupPosterCellModel.swift
//  MasterBoy
//
//  Created by kyson on 2024/9/20.
//

import Foundation
import YYText


class MBDGroupPosterCellModel : MBDGroupDetailCommonCellModel {
    var groupPosterTextLayout : YYTextLayout?
    static let MarginTop : CGFloat = 0
    static let MarginBottom : CGFloat = 10
    static let MarginDescLabelLeftAndRight : CGFloat = 7

    override var groupDetail: MBDGroupDetailModel! {
        didSet {
            let groupInfo = self.groupDetail.groupPoster ?? "无名人士"
            
            let postTime = MBDTimeUitls.time2CurrentTime(time: self.groupDetail.createTime)

            let postInfo = groupInfo + "    " + postTime
            let groupDetailAttributeString = NSMutableAttributedString(string: postInfo )
            groupDetailAttributeString.yy_font = UIFont.systemFont(ofSize: 14)
            groupDetailAttributeString.yy_lineSpacing = 4
            groupDetailAttributeString.setDynamicTextColor()
            
            let groupDetailContainer = YYTextContainer()
            
            let groupDetailWidth = CGRectGetWidth(UIScreen.main.bounds) - MBDGroupPosterCellModel.MarginLeftAndRightBackgroundView * 2 - MBDGroupPosterCellModel.MarginDescLabelLeftAndRight
            groupDetailContainer.size = CGSizeMake(groupDetailWidth , CGFLOAT_MAX)
            let groupDetailLayout = YYTextLayout(container: groupDetailContainer, text: groupDetailAttributeString)
            
            self.groupPosterTextLayout = groupDetailLayout
        }
    }
    
    override func cellHeight() -> CGFloat {
        return MBDGroupPosterCellModel.MarginTop + (self.groupPosterTextLayout?.textBoundingSize.height ?? 0) + MBDGroupPosterCellModel.MarginBottom
    }
}
